package com.swufestu.hello;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import java.text.BreakIterator;

public class ConfigActivity extends AppCompatActivity {

    private  static  final String TAG = "ConfigActivity";
    private EditText dollarText, euroText, thbText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);

        Intent intent = getIntent();
        Float dollar2 = intent.getFloatExtra("dollar_rate_key",0.0f);
        Float euro2 = intent.getFloatExtra("euro_rate_key",0.0f);
        Float thb2 = intent.getFloatExtra("thb_rate_key",0.0f);

        Log.i(TAG,"onCreate: dollar2="+dollar2);
        Log.i(TAG,"onCreate: euro2="+euro2);
        Log.i(TAG,"onCreate: thb2="+thb2);

        dollarText = findViewById(R.id.txt_dollar);
        euroText = findViewById(R.id.txt_euro);
        thbText = findViewById(R.id.txt_thb);

        //将汇率输入到控件
        dollarText.setText(String.valueOf(dollar2));
        euroText.setText(String.valueOf(euro2));
        thbText.setText(String.valueOf(thb2));
    }

    public void save(View btn){
        Log.i(TAG,"save:");
        //重新获取新的汇率数据
        float dollar = Float.parseFloat(dollarText.getText().toString());
        float euro = Float.parseFloat(euroText.getText().toString());
        float thb = Float.parseFloat(thbText.getText().toString());

        Log.i(TAG,"save: dollar=" + dollar);
        Log.i(TAG,"save: euro=" + euro);
        Log.i(TAG,"save: thb=" + thb);

//        Intent first = new Intent(this,first_activity.class);
        Intent first = getIntent();
        first.putExtra("dollar_key",dollar);
        first.putExtra("euro_key",euro);
        first.putExtra("thb_key",thb);

        setResult(3,first);
        finish();
    }
}